#include "hzpch.h"
#include "Log.h"
#include <spdlog/sinks/stdout_color_sinks.h>
#include "spdlog/sinks/basic_file_sink.h"

namespace SCION_UTIL
{

  std::shared_ptr<spdlog::logger> Log::s_CoreLogger;

  void Log::Init()
  {
    // 创建控制台sink
    auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
    console_sink->set_level(spdlog::level::trace);

    // 创建文件sink - 默认logs保存路径，文件
    auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/scion_editor.log", false);
    file_sink->set_level(spdlog::level::trace);

    // 创建同时输出到控制台和文件的logger
    std::vector<spdlog::sink_ptr> sinks{console_sink, file_sink};
    s_CoreLogger = std::make_shared<spdlog::logger>("SCION_UTIL", sinks.begin(), sinks.end());

    // 设置日志模式
    // 精确到毫秒
    spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%n] [%^%l%$] %v");
    s_CoreLogger->set_level(spdlog::level::trace);

    spdlog::register_logger(s_CoreLogger);
    spdlog::set_default_logger(s_CoreLogger);

    s_CoreLogger->info("Log System Initialized with file output!");
  }

  void Log::Info(const std::string &message)
  {
    s_CoreLogger->info(message);
  }

  void Log::Warn(const std::string &message)
  {
    s_CoreLogger->warn(message);
  }

  void Log::Error(const std::string &message)
  {
    s_CoreLogger->error(message);
  }

}
